<?php
function xmp($o, $add_inf = ''){
    echo '|********|<xmp>';
    echo $add_inf; print_r($o);
    echo '</xmp>|********|<br>';
}

function stop($o){
    xmp($o);
    exit;
}

function print_vars(){
    if(defined('IS_PROD_SITE') && IS_PROD_SITE==='true'){
        return;
    }
    $args = func_get_args();
    $output = call_user_func_array("print_vars2",$args);
    echo '<pre style="font-family: Courier New;font-size:12px;text-align:left">';
    echo htmlspecialchars($output);
    echo '</pre>';
}

function print_vars2(){
    $output = '';
    $args = func_get_args();
    foreach($args as $arg){
        $type = gettype($arg);
        if($type == 'boolean')$output .= $arg == true ? 'true':'false' ;
        else if(in_array($type,array('integer','double','string')))$output .= $arg ;
        else if(in_array($type,array('array','object')))$output .=print_r($arg,true);
        else if(in_array($type,array('NULL','unknown type')))$output .= $type;
        else if($type == 'resource')$output .= '['.get_resource_type($arg).']'.$arg;
        else $output .= 'unknow';
        $output .= "\n";
    }
    return $output;
}

function trace_log($text , $file = ''){
    if(defined('IS_PROD_SITE') && IS_PROD_SITE==='true'){
        return;
    }
    if(!is_string($text)){
        $text = print_r($text,true);
    }
    if($file == ''){
        $file = 'trace.log';
    }
    $fp = fopen($file,'a');
    fwrite($fp , date('Y-m-d H:i:s ') . "\r\n" . $text);
    fclose($fp);
}

/**
 * @author sunyichi@163.com (2012-2-24)
 */
function getAllGetParams($exclude_array = ''){
    if (!is_array($exclude_array)) $exclude_array = array($exclude_array);
    $get_url = '';
    $CHttp=new CHttpSession();
    if (is_array($_GET) && (sizeof($_GET) > 0)) {
        reset($_GET);
        while (list($key, $value) = each($_GET)) {
            if (is_array($value)) {
                foreach ($value as $k => $v) {
                    $get_url .= "{$key}%5B{$k}%5D={$v}" . '&';
                }
            } elseif ( (strlen($value) > 0) && ($key != $CHttp->getSessionName()) && (!in_array($key, $exclude_array)) && (!in_array($key, array('utm_source','utm_medium','utm_campaign','utm_term','OVRAW','OVADID','OVKEY','x','y','error'))) ) {
                $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';
            }
        }
    }
    $get_url = trim($get_url, '&');
    return $get_url;
}

/**
 * check current client is a China clent
 * @return boolean
 */
function isChinaClient(){
    $CHttp=new CHttpRequest();
    $client_ip = $CHttp->getUserHostAddress();
    Yii::import('sun.extensions.Ip2city');
    $ip = new Ip2city();
    return $ip->checkIpInRange($client_ip);
}

function getIpAddress() {
    $realip = '';
    $unknown = 'unknown';
    if (isset($_SERVER)){
        if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)){
            $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
            foreach($arr as $ip){
                $ip = trim($ip);
                if ($ip != 'unknown'){
                    $realip = $ip;
                    break;
                }
            }
        }else if(isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], $unknown)){
            $realip = $_SERVER['HTTP_CLIENT_IP'];
        }else if(isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown)){
            $realip = $_SERVER['REMOTE_ADDR'];
        }else{
            $realip = $unknown;
        }
    }else{
        if(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), $unknown)){
            $realip = getenv("HTTP_X_FORWARDED_FOR");
        }else if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), $unknown)){
            $realip = getenv("HTTP_CLIENT_IP");
        }else if(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), $unknown)){
            $realip = getenv("REMOTE_ADDR");
        }else{
            $realip = $unknown;
        }
    }
    $realip = preg_match("/^([0-9]{1,3}.){3}[0-9]{1,3}$/", $realip, $matches) ? $matches[0] : $unknown;
    return $realip;
}

/**
 * Get correct image url
 *
 * @param string $imgUrl
 * @param string $baseUrl
 * @param string $mainImageUrl
 * @return string
 */
function getImageUrl($imgUrl,$baseUrl='',$mainImageUrl='') {
    $imgUrl = rawurldecode($imgUrl);
    if (preg_match('/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/', $imgUrl)) {
        $image_final_main_name = $imgUrl;
    } else {
        $image_final_main_name = $baseUrl . $imgUrl;
    }
    $image_final_main_name = preg_replace('/\/\/images\//', '/images/', $image_final_main_name);
    return $image_final_main_name;
}

function catalogUrl() {
    if (Yii::app()->request->isSecureConnection == 1) {
        return rtrim(Yii::app()->params['frontSecureUrl'],'/');
    } else {
        return rtrim(Yii::app()->params['frontUrl'],'/');
    }
}

// Check if year is a leap year
function isLeapYear($year) {
    if ($year % 100 == 0) {
        if ($year % 400 == 0) return true;
    }
    else {
        if (($year % 4) == 0) return true;
    }
    return false;
}

// Check date
function checkValidDate($date_to_check, $format_string, &$date_array) {
    $separator_idx = -1;
    $separators = array('-', ' ', '/', '.');
    $month_abbr = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
    $no_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

    $format_string = strtolower($format_string);
    if (strlen($date_to_check) != strlen($format_string)) {
        return false;
    }

    $size = count($separators);
    for ($i=0; $i<$size; $i++) {
        $pos_separator = strpos($date_to_check, $separators[$i]);
        if ($pos_separator != false) {
            $date_separator_idx = $i;
            break;
        }
    }

    for ($i=0; $i<$size; $i++) {
        $pos_separator = strpos($format_string, $separators[$i]);
        if ($pos_separator != false) {
            $format_separator_idx = $i;
            break;
        }
    }

    if ($date_separator_idx != $format_separator_idx) {
        return false;
    }

    if ($date_separator_idx != -1) {
        $format_string_array = explode( $separators[$date_separator_idx], $format_string );
        if (count($format_string_array) != 3) {
            return false;
        }
        $date_to_check_array = explode( $separators[$date_separator_idx], $date_to_check );
        if (count($date_to_check_array) != 3) {
            return false;
        }

        $size = count($format_string_array);
        for ($i=0; $i<$size; $i++) {
            if ($format_string_array[$i] == 'mm' || $format_string_array[$i] == 'mmm') $month = $date_to_check_array[$i];
            if ($format_string_array[$i] == 'dd') $day = $date_to_check_array[$i];
            if (($format_string_array[$i] == 'yyyy') || ($format_string_array[$i] == 'aaaa')) $year = $date_to_check_array[$i];
        }
    }
    else {
        if (strlen($format_string) == 8 || strlen($format_string) == 9) {
            $pos_month = strpos($format_string, 'mmm');
            if ($pos_month != false) {
                $month = substr( $date_to_check, $pos_month, 3 );
                $size = count($month_abbr);
                for ($i=0; $i<$size; $i++) {
                    if ($month == $month_abbr[$i]) {
                        $month = $i;
                        break;
                    }
                }
            }
            else {
                $month = substr($date_to_check, strpos($format_string, 'mm'), 2);
            }
        }
        else {
            return false;
        }
        $day = substr($date_to_check, strpos($format_string, 'dd'), 2);
        $year = substr($date_to_check, strpos($format_string, 'yyyy'), 4);
    }

    if (strlen($year) != 4) {
        return false;
    }
    if (!settype($year, 'integer') || !settype($month, 'integer') || !settype($day, 'integer')) {
        return false;
    }
    if ($month > 12 || $month < 1) {
        return false;
    }
    if ($day < 1) {
        return false;
    }
    if (isLeapYear($year)) {
        $no_of_days[1] = 29;
    }
    if ($day > $no_of_days[$month - 1]) {
        return false;
    }

    $date_array = array($year, $month, $day);
    return true;
}

//function to change the date format from '2008-12-31' to '12/31/2008' or '12/31/2008' to '2008-12-31'
function getDateDisp($date, $format='m/d/Y'){
    if($date!='') {
        $date_disp = strtotime($date);
        $date_return = date($format,$date_disp);
    } else {
        $date_return='';
    }
    return $date_return;
}

function dateAddDay($length,$format,$date_passed){
    $new_timestamp = -1;
    if($date_passed != ''){
        $date_passed_array = explode('/',$date_passed);
        $date_actual["mon"] = $date_passed_array[0];
        $date_actual["mday"] = $date_passed_array[1];
        $date_actual["year"] = $date_passed_array[2];
        switch(strtolower($format)){
            case 'd':
                $new_timestamp = @mktime(0,0,0,$date_actual["mon"],$date_actual["mday"]+$length,$date_actual["year"]);
                break;
            case 'm':
                $new_timestamp = @mktime(0,0,0,$date_actual["mon"]+$length,$date_actual["mday"],$date_actual["year"]);
                break;
            case 'y':
                $new_timestamp = @mktime(0,0,0,$date_actual["mon"],$date_actual["mday"],$date_actual["year"]+$length);
                break;
            default:
                break;
        }
        return @date('m/d/Y',$new_timestamp);
    }else{
        return '';
    }
}

function GetDateDifference($StartDateString=NULL, $EndDateString=NULL) {
    $SDSplit = explode('/',$StartDateString);
    $StartDate = mktime(0,0,0,$SDSplit[0],$SDSplit[1],$SDSplit[2]);
    $EDSplit = explode('/',$EndDateString);
    $EndDate = mktime(0,0,0,$EDSplit[0],$EDSplit[1],$EDSplit[2]);

    $y1 = date("Y", $StartDate);
    $m1 = date("m", $StartDate);
    $d1 = date("d", $StartDate);
    $y2 = date("Y", $EndDate);
    $m2 = date("m", $EndDate);
    $d2 = date("d", $EndDate);

    $diff = 0;
    if(($EndDate - $StartDate)<=0) {
        // Start date is before or equal to end date!
        $diff  = 0;
    } else {
        $y = $y2 - $y1;
        $m = $m2 - $m1;
        $d = $d2 - $d1;
        $daysInMonth = date("t",$StartDate);
        if($d<0) {
            $m--;
            $d = $daysInMonth + $d;
        }
        if($m<0) {
            $y--;
            $m = 12 + $m;
        }

        if($y>0) {
            $diff = $y;
        }
        if($m>0) {
            $diff += $m/12;
        }
        if($d>0) {
            $diff += $d/365;
        }
    }
    return $diff;
}

/**
 * Secure a string to avoid security issues (mainly used to solve the PCI scanner issues).
 */
function secureString($str) {
    // it's actually not needed for security since strip_tags
    // already remove the tags, but the PCI scanner still finds
    // problems if we don't remove the contents of the <script> tag.
    // Remove the contents of <script>*</script>
    $safe_str = preg_replace_callback('#<script(.*?)>(.*?)</script>#is', function($r){return '';}, $str);
    // Remove the contents of <iframe>*</iframe>
    $safe_str = preg_replace_callback('#<iframe(.*?)>(.*?)</iframe>#is', function($r){return '';}, $str);
    $safe_str = preg_replace_callback('/%3C.*%3E/', function($r){return '';}, $safe_str);
    // The PCI scanner fails even it if sees an "alert()"
    $safe_str = preg_replace_callback('#alert\((.*?)\)#is', function($r){return '';}, $safe_str);
    // The 360 scanner fail use the prompt
    $safe_str = preg_replace_callback('#prompt\((.*?)\)#is', function($r){return '';}, $safe_str);

    // Replace all occurrences of the search string with the replacement string:
    $search_arr = array('onclick=', 'onfocus=');
    $safe_str = str_replace($search_arr, '', $safe_str);
    // Now strip the tags:
    $safe_str = strip_tags($safe_str);
    // Convert special characters to HTML entities
    $safe_str = htmlspecialchars($safe_str);

    return $safe_str;
}

/**
 * Secure a array to avoid  PCI security issue
 */
function secureArray($data){
    if(is_array($data)){
       foreach($data as $k=>$v){
           if(preg_match('/^[a-z0-9_-]+$/i' ,$k)){
                $data[$k] = secureArray($v);
           }else{
                unset($data[$k]);
           }
       }
    }else{
        $data = secureString($data);
    }
   return $data ;
}

/**
 * Get string length, chinese string=+2, english string+1
 */
function mbstrlen($str,$encoding="utf8"){
    if(($len = strlen($str)) == 0) {
        return 0;
    }

    $encoding = strtolower($encoding);
    if($encoding == "utf8" or $encoding == "utf-8") {
        $step = 3;
    } elseif($encoding == "gbk" or $encoding == "gb2312") {
        $step = 2;
    } else {
        return false;
    }

    $count = 0;
    for($i=0; $i<$len; $i++) {
        //如果字节码大于127，则根据编码跳几个字节
        if(ord($str{$i}) >= 0x80) {
            $i = $i + $step - 1;//之所以减去1，因为for循环本身还要$i++
            $count += 2;
        } else {
            $count += 1;
        }
    }
    return $count;
}

/**
 * Returns the portion of string specified by the start and length parameters, chinese string=+2, english string+1
 */
function mbsubstr($str,$start=0,$lenth=null,$encoding="utf8"){
    if(($len = strlen($str)) == 0) {
        return '';
    }

    $encoding = strtolower($encoding);
    if($encoding == "utf8" or $encoding == "utf-8") {
        $step = 3;
    } elseif($encoding == "gbk" or $encoding == "gb2312") {
        $step = 2;
    } else {
        return '';
    }

    if($lenth == null) {
        $lenth = mbstrlen($str,$encoding);
    }

    $count = 0;
    $string = '';
    $start_str = 0;
    $end = $start + $lenth;    for($i=0; $i<$len; $i++) {
        if($count >= $start + $lenth) break;
        if($start == $count || $start == $count-1) {
            $start_str = 1;
        }
        //如果字节码大于127，则根据编码跳几个字节
        if(ord($str{$i}) >= 0x80) {
            if($start_str) {
                $new_word = '';
                if($step == 2) {
                    $new_word .= chr(ord($str{$i}));
                    $new_word .= chr(ord($str{$i+1}));
                } else {
                    $new_word .= chr(ord($str{$i}));
                    $new_word .= chr(ord($str{$i+1}));
                    $new_word .= chr(ord($str{$i+2}));
                }
                $string .= $new_word;
            }
            $i = $i + $step - 1;//之所以减去1，因为for循环本身还要$i++
            $count += 2;
        } else {
            if($start_str) {
                $string .= $str[$i];
            }
            $count += 1;
        }
    }
    return $string;
}
function get_cart_add_update_extra_values($fieldname, $fieldvalue, $extra_values_str=''){
    if(!empty($extra_values_str)){
        $extra_values_array = explode("|##!##|", $extra_values_str);
        $total_ext_values = count($extra_values_array)-1;
        $new_extra_values_str = '';
        $update_count = 0;
        for($ext=0; $ext<$total_ext_values; $ext++){
            $get_field_info = explode("|#|", $extra_values_array[$ext]);
            if($get_field_info[0] == $fieldname){
                $get_field_info[1] = $fieldvalue;
                $update_count++;
            }
            if(!empty($get_field_info[0]) && !empty($get_field_info[1])){
                $new_extra_values_str .= $get_field_info[0] . '|#|' . $get_field_info[1] . '|##!##|';
            }
        }
        if($update_count==0){
            if(!empty($fieldname) && !empty($fieldvalue)){
                $new_extra_values_str .= $fieldname . '|#|' . $fieldvalue . '|##!##|';
            }
        }
    }
    else{
        $new_extra_values_str = $fieldname . '|#|' . $fieldvalue . '|##!##|';
    }
    return $new_extra_values_str;
}
function get_cart_get_extra_field_value($fieldname, $extra_values_str=''){
    $fieldvalue = '';
    if(!empty($extra_values_str)){
        $extra_values_array = explode("|##!##|", $extra_values_str);
        $total_ext_values = count($extra_values_array)-1;
        $new_extra_values_str = '';
        for($ext=0; $ext<$total_ext_values; $ext++){
            $get_field_info = explode("|#|", $extra_values_array[$ext]);
            if($get_field_info[0] == $fieldname){
                $fieldvalue = $get_field_info[1];
            }
        }
    }
    return $fieldvalue;
}
function datetimeShort($raw_datetime) {
    if ( ($raw_datetime == '0000-00-00 00:00:00') || ($raw_datetime == '') ) return false;

    $year = (int)substr($raw_datetime, 0, 4);
    $month = (int)substr($raw_datetime, 5, 2);
    $day = (int)substr($raw_datetime, 8, 2);
    $hour = (int)substr($raw_datetime, 11, 2);
    $minute = (int)substr($raw_datetime, 14, 2);
    $second = (int)substr($raw_datetime, 17, 2);

    return strftime('%m/%d/%Y  %H:%M:%S', mktime($hour, $minute, $second, $month, $day, $year));
}
function array_intersect_two(array $arr){
    $new_arr=array();
    if(empty($arr)){
        return $arr;
    }
    sort($arr);
    if(count($arr)>1){
        foreach($arr as $k=>$row){
            if(count($arr)==2){
                return array_unique(array_intersect($row,$arr[$k+1]));
            }
            if($k==0){
                $new_arr=array_intersect($row,$arr[$k+1]);
            }else{
                $new_arr=array_intersect($new_arr,$arr[$k+1]);
            }
            if($k==count($arr)-2){
                break;
            }
        }
        return array_unique($new_arr);
    }else{
        return array_unique($arr[0]);
    }
}

function array_bing_two(array $arr){
    $new_arr=array();
    if(empty($arr)){
        return $arr;
    }
    sort($arr);
    if(count($arr)>1){
        foreach($arr as $k=>$row){
            if(count($arr)==2){
                return array_unique(array_merge($row,$arr[$k+1]));
            }
            if($k==0){
                $new_arr=array_merge($row,$arr[$k+1]);
            }else{
                $new_arr=array_merge($new_arr,$arr[$k+1]);
            }
            if($k==count($arr)-2){
                break;
            }
        }
        return array_unique($new_arr);
    }else{
        return array_unique($arr[0]);
    }
}

function getArrColumn($arr,$key){
    $new_arr=array();
    if(is_array($arr)){
        foreach($arr as $v){
            $new_arr[]=$v[$key];
        }
    }
    return $new_arr;
}

function phoneValidateCode($phone,$text='VALIDATE_CODE'){
    $code=mt_rand(1000,9999);
    Yii::app()->session['PhoneVerificationCode']=array('code'=>md5(md5($code).'xtours'.$phone),'time'=>time());
    $result=Yii::app()->smsSender->sendSMS($phone,sprintf(yii::t('login',$text),$code));
    return $result;
}

function unsetPhoneCode(){
    unset(Yii::app()->session['PhoneVerificationCode']);
}

function checkPhoneCode($code='',$phoneCode=''){
    if($code!='' && $phoneCode!=''){
        $sessionCode=Yii::app()->session['PhoneVerificationCode'];
        if(empty($sessionCode) || md5(md5($code).'xtours'.$phoneCode)!=$sessionCode['code'] || time()>$sessionCode['time']+60*30){
            return false;
        }else{
            return true;
        }
    }else{
        return false;
    }
}

function emailValidateCode($email,$content='VALIDATE_CODE',$title='EMAIL_TITLE'){
    $code=mt_rand(1000,9999);
    Yii::app()->session['EmailVerificationCode']=array('code'=>md5(md5($code).'xtours'.$email),'time'=>time());
    $email_content = Yii::app()->mailer->loadMailContent(
        'message_push',
        array(
            'content' => sprintf(yii::t('login',$content),$code)
        ),
        'default'
    );
    $to_email = $email;
    $email_title = yii::t('login',$title);
    $from_email = STORE_OWNER.'<'.STORE_OWNER_EMAIL_ADDRESS.'>';
    return Yii::app()->mailer->send($to_email, $email_title, $email_content, $from_email);
}

function unsetEmailCode(){
    unset(Yii::app()->session['EmailVerificationCode']);
}

function checkEmailCode($code='',$email=''){
    if($code!='' && $email!=''){
        $sessionCode=Yii::app()->session['EmailVerificationCode'];
        if(empty($sessionCode) || md5(md5($code).'xtours'.$email)!=$sessionCode['code'] || time()>$sessionCode['time']+60*30){
            return false;
        }else{
            return true;
        }
    }else{
        return false;
    }
}

function isSSL()
{
    if (!isset($_SERVER['HTTPS'])) {
        return false;
    }
    if ($_SERVER['HTTPS'] === 1) {  //Apache
        return true;
    } elseif ($_SERVER['HTTPS'] === 'on') { //IIS
        return true;
    } elseif ($_SERVER['SERVER_PORT'] == 443) { //其他
        return true;
    }
    return false;
}

/**
* POST
* @param string $url
* @param array $param
* @param boolean $post_file 是否文件上传
* @return string content
*/
function http_post($url, $param, $post_file = false) {
    $oCurl = curl_init();
    if (stripos($url, "https://") !== FALSE) {
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
    }
    if (is_string($param) || $post_file) {
        $strPOST = $param;
    } else {
        $strPOST=http_build_query($param);
    }
    curl_setopt($oCurl, CURLOPT_URL, $url);
    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($oCurl, CURLOPT_POST, true);
    curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST);
    $sContent = curl_exec($oCurl);
    $aStatus = curl_getinfo($oCurl);
    curl_close($oCurl);
    if (intval($aStatus["http_code"]) == 200) {
        return $sContent;
    } else {
        return false;
    }
}

/**
 * get
 * @param $url
 * @return bool|mixed
 */
function http_get($url) {
    $oCurl = curl_init();
    if (stripos($url, "https://") !== FALSE) {
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
    }
    curl_setopt($oCurl, CURLOPT_URL, $url);
    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
    $sContent = curl_exec($oCurl);
    $aStatus = curl_getinfo($oCurl);
    curl_close($oCurl);
    header('Content-type:text/html;charset=utf-8');
    echo $sContent;
    if (intval($aStatus["http_code"]) == 200) {
        return $sContent;
    } else {
        return false;
    }
}

function getParabolaArray($p=-1, $vertex=array(94,18), $start=array(90,2), $end=array(98,2)){
    $distribution_data = array();
    if($start[0]<$end[0]){
        $s = $start[0];
        $t = $end[0];
    }else{
        $s = $end[0];
        $t = $start[0];
    }
    for($x=$s; $x<=$t; $x++){
        $y = $p*($x-$vertex[0])*($x-$vertex[0])+$vertex[1];
        for($i=1; $i<=$y; $i++){
            $distribution_data[] = $x;
        }
    }
    return $distribution_data;
}

function getThumbName($src,$width=0,$height=0){
    $pathinfo = pathinfo($src);
    return $pathinfo['filename'] . '_' . $width . '_'.$height.'.' . $pathinfo['extension'];
}

function getSourceName($src,$width=0,$height=0){
    $str='_'.$width.'_'.$height;
    $index=strpos($src,$str);
    if($index==false){
        return $src;
    }else{
        $info=pathinfo($src);
        return substr($src,0,$index).'.'.$info['extension'];
    }
}
?>